package my.sample.quartz;

import static org.quartz.CronScheduleBuilder.cronSchedule;
import static org.quartz.JobBuilder.newJob;
import static org.quartz.TriggerBuilder.newTrigger;

import java.util.Date;

import org.quartz.CronTrigger;
import org.quartz.JobDetail;
import org.quartz.Scheduler;
import org.quartz.SchedulerException;
import org.quartz.SchedulerFactory;
import org.quartz.impl.StdSchedulerFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class LogTimes {

	private static Logger log = null;
	
	public static void main(String[] args) throws SchedulerException {

		log = LoggerFactory.getLogger(LogTimes.class);
		
		SchedulerFactory fact = new StdSchedulerFactory();
		Scheduler scheduler = fact.getScheduler();
		System.out.println("scheduler name: " + scheduler.getSchedulerName());
		scheduler.start();
		
		// job
		JobDetail job = newJob(SimpleJob.class).withIdentity("myFirst", "myGroup").build();
		
		// start time
		
		Date start = new Date();
		start.setDate(19);
		start.setMonth(9);
		start.setHours(17);
		start.setMinutes(12);
		start.setSeconds(00);
		System.out.println("start : " + start);
		 
		Date stop = new Date();
		stop.setDate(8);
		stop.setMonth(10);
		stop.setHours(17);
		stop.setMinutes(20);
		stop.setSeconds(00);
		System.out.println("stop : " + stop);

		
		// trigger
		CronTrigger trigger = newTrigger()
				.withIdentity("myTrigger", "myGroup")
				.startAt(start)
				.endAt(stop)
//				.withSchedule(cronSchedule("* 40 11 17 Oct ? 2013")).build();
				.withSchedule(cronSchedule("0 10 15 ? * SAT")).build();
		// 0 30 15 10,19 *  *
				
		scheduler.scheduleJob(job, trigger);
		
	}

}
